
var LODOP; //声明为全局变量
/*取消单*/
function channel(idorderHead){
    if (/(Android)/i.test(navigator.userAgent)) {
        alert("手机端不允许打印!")
        return ;
    } else if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
        alert("手机端不允许打印!")
        return ;
    } else {
        console.log("i`am computer")
    }
    var url =  prefix + '/printSmall/'+idorderHead;
    $.getJSON(url,function (json) {
        if (json.code != 0) {
            $.modal.msgWarning(json.msg)
            return;
        }
        //设置为小票打印机
        LODOP.SET_PRINT_MODE("WINDOW_DEFPRINTER","NPI24D743 (HP LaserJet Pro MFP M226dw)");
        //LODOP.SET_PRINTER_INDEX(2);
        LODOP.PRINT_INIT("打印任务名");               //首先一个初始化语句
        LODOP.SET_PRINT_STYLEA(2,"FontSize",8);
        LODOP.SET_PRINT_STYLEA(2,"FontName","宋体");
        LODOP.ADD_PRINT_TEXT(128,2,277,20,"提货日期: "+json.data.date);
        LODOP.ADD_PRINT_TEXT(110,2,150,20,"地址: "+json.data.order.city +" "+ json.data.order.town);
        LODOP.ADD_PRINT_TEXT(91,2,110,20,"订单号: "+ json.data.order.no);
        LODOP.ADD_PRINT_TEXT(67,89,100,20,"***************");
        LODOP.ADD_PRINT_TEXT(50,89,100,20,"*     取消    *");
        LODOP.ADD_PRINT_TEXT(36,89,100,20,"***************");
        LODOP.ADD_PRINT_TEXT(169,1,100,20,"种类");
        LODOP.ADD_PRINT_TEXT(151,1,276,20,"- - - - - - - - - - - - - - - - - - - - - - ");
        LODOP.ADD_PRINT_TEXT(170,200,38,20,"数量");
        LODOP.ADD_PRINT_TEXT(170,241,34,20,"价钱");
        let itemList = json.data.itemList;
        $(itemList).each(function(index,item){
            console.log(item)
            console.log(index)
            LODOP.ADD_PRINT_TEXT(188+index*20,2,203,20,item.nameProduct);
            LODOP.ADD_PRINT_TEXT(188+index*20,201,40,20,item.count);
            LODOP.ADD_PRINT_TEXT(188+index*20,239,39,20,item.priceProduct);
        })
        //LODOP.PREVIEW();
        LODOP.PRINT();                               //最后一个打印(或预览、维护、设计)语句
        //设置为默认打印机
        LODOP.SET_PRINT_MODE("WINDOW_DEFPRINTER","HP LaserJet Pro MFP M225-M226 PCL 6");
    })

}
/*改单*/
function updateP(url, data) {
    if (/(Android)/i.test(navigator.userAgent)) {
        alert("手机端不允许打印!")
        return ;
    } else if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
        alert("手机端不允许打印!")
        return ;
    } else {
        console.log("i`am computer")
    }
    var config = {
        url: url,
        type: "post",
        dataType: "json",
        data: data,
        success: function(result) {
            updatePP(result)
            alert("修改成功 请刷新")
             $.modal.close();
            //if(date){
               // window.parent.$.modal.openTab("每日订单详情",date,true)
            //}else{
                $.operate.successCallback(result);
            //}
           // $.operate.successCallback(result);
        }
    };
    $.ajax(config)

}

function updatePP(json){
    let data = json.data;
    let oldMap = data.oldMap;
    let newMap = data.newMap;
    let oldDate = oldMap.date;
    let newDate = newMap.date;
    let oldItemList = oldMap.itemList;
    let newItemList = newMap.itemList;
    let oldOrder = oldMap.order;
    let newOrder = newMap.order;
    setTimeout(function () {
        //设置为小票打印机
        LODOP.SET_PRINT_MODE("WINDOW_DEFPRINTER","NPI24D743 (HP LaserJet Pro MFP M226dw)");
        //LODOP.SET_PRINTER_INDEX(2);
        LODOP.PRINT_INIT("打印任务名");               //首先一个初始化语句
        LODOP.SET_PRINT_STYLEA(2,"FontSize",8);
        LODOP.SET_PRINT_STYLEA(2,"FontName","宋体");
        //LODOP.ADD_PRINT_TEXT(100, 50, 100, 20, "文本内容一");//然后多个ADD语句及SET语句
        LODOP.ADD_PRINT_TEXT(55,109,100,20,"***************");
        LODOP.ADD_PRINT_TEXT(72,109,100,20,"*     改单    *");
        LODOP.ADD_PRINT_TEXT(90,109,100,20,"***************");
        LODOP.ADD_PRINT_TEXT(131,5,100,20,"订单号: "+newOrder.no);
        LODOP.ADD_PRINT_TEXT(152,5,135,20,"地址: "+newOrder.city+""+newOrder.town);
        LODOP.ADD_PRINT_TEXT(172,5,303,20,"- - - - - - - - - - - - - - - - - - - - - - - - ");
        LODOP.ADD_PRINT_TEXT(194,109,100,20,"***************");
        LODOP.ADD_PRINT_TEXT(212,109,100,20,"*    改单前   *");
        LODOP.ADD_PRINT_TEXT(226,109,100,20,"***************");
        LODOP.ADD_PRINT_TEXT(262,5,289,20,"提货日期: "+oldDate);
        LODOP.ADD_PRINT_TEXT(291,5,100,20,"种类");
        LODOP.ADD_PRINT_TEXT(291,215,39,20,"数量");
        LODOP.ADD_PRINT_TEXT(290,248,41,20,"价钱");
        $(oldItemList).each(function(index,item){
            LODOP.ADD_PRINT_TEXT(309+index*20,5,203,20,item.nameProduct);
            LODOP.ADD_PRINT_TEXT(309+index*20,214,42,20,item.count);
            LODOP.ADD_PRINT_TEXT(309+index*20,248,55,20,item.priceProduct);
        })
        let size = $(oldItemList).length;
        LODOP.ADD_PRINT_TEXT(338+size*20,5,307,20,"- - - - - - - - - - - - - - - - - - - - - - - - ");
        LODOP.ADD_PRINT_TEXT(361+size*20,109,100,20,"***************");
        LODOP.ADD_PRINT_TEXT(377+size*20,109,100,20,"*    改单后   *");
        LODOP.ADD_PRINT_TEXT(395+size*20,109,100,20,"***************");
        LODOP.ADD_PRINT_TEXT(420+size*20,5,308,20,"提货日期: "+newDate);
        LODOP.ADD_PRINT_TEXT(450+size*20,5,100,20,"种类");
        LODOP.ADD_PRINT_TEXT(450+size*20,215,39,20,"数量");
        LODOP.ADD_PRINT_TEXT(450+size*20,248,57,20,"价钱");
        $(newItemList).each(function(index,item){
            LODOP.ADD_PRINT_TEXT(471+size*20+index*20,5,206,20,item.nameProduct);
            LODOP.ADD_PRINT_TEXT(471+size*20+index*20,215,53,20,item.count);
            LODOP.ADD_PRINT_TEXT(470+size*20+index*20,248,56,20,item.priceProduct);
        })
        LODOP.PREVIEW();
        //LODOP.PRINT();                               //最后一个打印(或预览、维护、设计)语句
        //设置为默认打印机
        LODOP.SET_PRINT_MODE("WINDOW_DEFPRINTER","HP LaserJet Pro MFP M225-M226 PCL 6");
    }, 1000)
}
/*新单*/
function p(idorderHead) {
    console.log(idorderHead)
    if (/(Android)/i.test(navigator.userAgent)) {
        alert("手机端不允许打印!")
        return ;
    } else if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
        alert("手机端不允许打印!")
        return ;
    } else {
        console.log("i`am computer")
    }

    var url =  prefix + '/printSmall/'+idorderHead;
    $.getJSON(url,function (json) {
        if(json.code!=0){
            $.modal.msgWarning(json.msg)
            return;
        }

        var map = json.data;
        let order = map.order;
        let date = map.date;
        let itemList = map.itemList;
        console.log(order)
            //设置为小票打印机
            LODOP.SET_PRINT_MODE("WINDOW_DEFPRINTER","NPI24D743 (HP LaserJet Pro MFP M226dw)");
            //LODOP.SET_PRINTER_INDEX(2);
            LODOP.PRINT_INIT("打印任务名");               //首先一个初始化语句
            LODOP.SET_PRINT_STYLEA(2,"FontSize",8);
            LODOP.SET_PRINT_STYLEA(2,"FontName","宋体");
            //LODOP.ADD_PRINT_TEXT(100, 50, 100, 20, "文本内容一");//然后多个ADD语句及SET语句
            LODOP.ADD_PRINT_TEXT(53,97,100,20,"***************");
            LODOP.ADD_PRINT_TEXT(77,97,100,20,"***************");
            LODOP.ADD_PRINT_TEXT(65,97,100,20,"*    新订单   *");
            LODOP.ADD_PRINT_TEXT(120,14,100,20,"订单号: "+order.no);
            LODOP.ADD_PRINT_TEXT(215,14,257,20,"- - - - - - - - - - - - - - - - - - - - - ");
            LODOP.ADD_PRINT_TEXT(200,14,235,24,"提货日期: "+date);
            LODOP.ADD_PRINT_TEXT(183,14,145,23,"地址: "+order.city+" "+order.town);
            LODOP.ADD_PRINT_TEXT(147,14,145,23,"电话号码: "+order.phone);
            LODOP.ADD_PRINT_TEXT(133,14,100,20,"客户: "+order.clientName);
            LODOP.ADD_PRINT_TEXT(230,14,45,25,"种类");
            LODOP.ADD_PRINT_TEXT(230,211,33,25,"数量");
            LODOP.ADD_PRINT_TEXT(230,240,44,25,"价钱");
            $(itemList).each(function(index,item){
                LODOP.ADD_PRINT_TEXT(245+index*20,14,210,25,item.nameProduct);
                LODOP.ADD_PRINT_TEXT(245+index*20,211,50,25,item.count);
                LODOP.ADD_PRINT_TEXT(245+index*20,240,50,25,item.priceProduct);
            })
            LODOP.ADD_PRINT_TEXT(295,14,100,25,"备注: "+order.desc);
            LODOP.ADD_PRINT_TEXT(280,14,257,20,"- - - - - - - - - - - - - - - - - - - - - ");
            LODOP.PREVIEW();
            //LODOP.PRINT();                               //最后一个打印(或预览、维护、设计)语句
            //设置为默认打印机
            LODOP.SET_PRINT_MODE("WINDOW_DEFPRINTER","HP LaserJet Pro MFP M225-M226 PCL 6");
    })
}